<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no" />
		<title>礼品</title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/style.css" rel="stylesheet" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">礼品</h1>
		</header>
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper transparent">
			<div class="mui-scroll">
				<ul class="mui-table-view mui-grid-view mui-clearfix vshop-product" id="productsList">
					
				</ul>
			</div>
		</div>
		
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script src="../js/delayimg.min.js"></script>
		<script>
			var isnodata = false,
				page = 1;
			mui.init({
				pullRefresh : {
				    container:'#pullrefresh',
				    deceleration:0.0006,
				    up : {
					    contentrefresh : "正在加载...",
					    contentnomore:'已加载全部',
					    callback :function(){
					      	var self=this;
					      	if (!isnodata) {
					      		page++;
						        mui.ajax(URL+'api/UserCenter/GetUserCollectionProduct?pageNo='+page+'&pageSize=10',{
									dataType:'json',
									type:'get',
									timeout:10000,
									success:function(data){
										if(data.Success){
											var html='';
						                    if(data.Data.length>0){
												document.getElementById('productsList').insertAdjacentHTML('beforeend',initData(html,data));
												delayimg.render();
											}
						                    if (data.Total<=page*10) {isnodata = true;}
											self.endPullupToRefresh(isnodata);
					      					
										}
									},
									error:function(xhr,type,errorThrown){
										plus.nativeUI.toast('请求失败，请检查网络')
									}
								});
						    }else{
						    	self.endPullupToRefresh(isnodata);
						    }
				    	}
				    }
				},
				swipeBack: true
			});
			mui.plusReady(function() {
				var ws=plus.webview.currentWebview();
				ws.setStyle({scrollIndicator:'none'});
				var w=plus.nativeUI.showWaiting('',{padlock:true});
				mui.ajax(URL+'api/UserCenter/GetUserCollectionProduct?pageNo=1&pageSize=10',{
					dataType:'json',
					type:'get',
					timeout:10000,
					success:function(data){
						if(data.Success){
							var html='';
							if (data.Total<=10) {isnodata = true;}
							if(data.Data.length>0){
								
								document.getElementById('productsList').innerHTML=initData(html,data);
			                    delayimg.init();
							}else{
								var html='<div class="empty-show"><h4>还没有收藏任何商品</h4><button id="closeWv" class="mui-btn mui-btn-negative">马上去收藏</button></div>';
					        	document.getElementById('pullrefresh').innerHTML=html;
							}
							w.close();
							document.getElementById('pullrefresh').className="mui-content mui-scroll-wrapper";
						}
					},
					error:function(xhr,type,errorThrown){
						w.close();
						reloadWvLoad();
					}
				});
				
				function initData(html,data){
					for(var i=0; i<data.Data.length; i++){
						html+='<li class="mui-table-view-cell mui-media mui-col-xs-6">'+
                			'<div class="vshop-product-box">'+
								'<a data-id="'+data.Data[i].Id+'">'+
									'<div class="p-img"><b data-delay-background="'+data.Data[i].Image+'"></b></div>'+
									'<div class="mui-media-body">'+data.Data[i].ProductName+'</div>'+
									'<p class="vshop-product-price"><span>¥ '+data.Data[i].SalePrice+'</span></p>'+
								'</a>'+
							'</div>'+
	            		'</li>';
					}
					return html;
				}
				
				
				//添加列表项的点击事件
				mui('.mui-content').on('tap', '.vshop-product a', function() {
					var id = this.getAttribute('data-id');
					showProduct(id,'/');
				});
			});
			
		</script>
	</body>

</html>